package cn.bb.servlet;


import cn.bb.dao.UserDaoJdbc;
import cn.bb.pojo.User;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

public class UserServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        ApplicationContext app = new ClassPathXmlApplicationContext("spring.xml");
        UserDaoJdbc udj = app.getBean("userDao",UserDaoJdbc.class);
        List<User> list =udj.searchUser();
        resp.setContentType("text/html,charset=UTF-8");
        PrintWriter out = resp.getWriter();
        out.print(list.size());
        //System.out.println(list);
    }
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        doGet(req,resp);
    }
}
